import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/login",
    component: () => import("@/components/MyLogin.vue"),
  },
  {
    path: "/home",
    component: () => import("@/components/MyHome.vue"),
    children: [
      {
        path: "goods",
        component: () => import("@/components/menus/MyGoods.vue"),
      },
      {
        path: "orders",
        component: () => import("@/components/menus/MyOrders.vue"),
      },
      {
        path: "rights",
        component: () => import("@/components/menus/MyRights.vue"),
      },
      {
        path: "settings",
        component: () => import("@/components/menus/MySettings.vue"),
      },
      {
        path: "users",
        component: () => import("@/components/menus/MyUsers.vue"),
      },
      {
        path: "userinfo/:id",
        component: () => import("@/components/user/MyUserDetail.vue"),
        props: true,
      },
    ],
  },
];

// routes.beforeEach((to, from, next) => {
//   if (to.path === "login") {
//     next();
//   } else {
//     if (localStorage.getItem("token")) {
//       next();
//     } else {
//       next("/login");
//     }
//   }
// });

const router = new VueRouter({
  routes,
});

export default router;
